﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using EasyQuartz.Client.EasyAddJob.SchedulingServices;
using EasyQuartz.Client.Jobs;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace EasyQuartz.Client.EasyAddJob
{
	public class Program
	{
		const string ContextName = "JobsContext.xml";
		static SchedulerService service = new SchedulerService();
		static IApplicationContext context = new XmlApplicationContext(ContextName);

		static void Main()
		{
			Console.WriteLine("Loading context...");
			PendingTask pendingTask = (PendingTask)context.GetObject("PendingTask");

			// For each jobs.
			foreach (EasyJob item in pendingTask.Jobs)
			{
				// Global unique identifier.
				item.Id = Guid.NewGuid();
				
				// Invoke web service.
				AddJobResult result = service.AddJob(new AddJobArgs { EasyJob = item });
				
				if (!result.Succefull)
					Console.WriteLine("Warning: {0} not added.", item);
				else
					Console.Write("{0} added!", item);
			}
		}
	}

}
